<?php

namespace app\common\job;

use app\common\model\mycurrency\LeaseOrder;
use app\common\model\WechatChapterOrder;
use think\Db;
use think\Exception;
use think\Log;
use think\Queue;
use think\queue\Job;

class ChapterOrder {

    /**
     * 免押操作超时处理
     * @param Job $job
     * @param $data
     * @throws \think\exception\DbException
     */
    public function operateTimeout(Job $job, $data) {
        if ($job->attempts() > 3) {
            $job->delete();
        }
        $chapter_order_id = $data['chapter_order_id'];
        $chapter_order = WechatChapterOrder::get($chapter_order_id);
        if($chapter_order){
            if($chapter_order->state == WechatChapterOrder::STATE_CREATED){//订单状态 = 商户已创建服务订单
                //修改免押订单状态
                $chapter_order->state =  WechatChapterOrder::STATE_EXPIRED;
                $chapter_order->loseefficacy_time  = time();
                $chapter_order->save();

                //取消租赁订单 - 根据项目写具体逻辑
                trace(["8========================处理lease_order_id报错问题_operateTimeout==============================" => $chapter_order],'error');
                LeaseOrder::orderCancell($chapter_order->lease_order_id,LeaseOrder::CANCELL_TYPE_MIANYACHAOSHI);
            }
        }
        $job->delete();
    }


}